import sys                                 # 导入sys模块
#from PyQt6.QtWidgets import *              # 导入PyQt6的QtWidgets模块
from PyQt6.QtGui import *                   # 导入PyQt6的QtGui模块
from src.compents.ImageView import ImageView
from PyQt6.QtWidgets import QApplication, QMainWindow, QDockWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, \
    QWidget, QMdiArea


class MdiArea(QDockWidget):
    '''窗口管理器'''
    def __init__(self, parent=None):        # 构造函数，初始化窗口
        super().__init__(parent)   # 调用父类的构造函数
        self.mdi = QMdiArea()                # 实例化QMdiArea区域对象并赋值给mdi属性
        self.setWindowTitle("Work Place")       # 设置窗口标题为'Work Place'
        self.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetFloatable|QDockWidget.DockWidgetFeature.DockWidgetMovable) #不允许关闭
        #self._test() #作为测试

    def create_sub_window(self, object):
        '''
        创建实例对应的子窗口
        :param object: 窗口实例
        :return: None
        '''
        sub = object #直接拿取窗口实例
        self.mdi.addSubWindow(sub)
        sub.show()

    def _test(self):
        self.imageview = ImageView()
        self.create_sub_window(self.imageview)
        self.setWidget(self.mdi)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = MdiArea()
    demo.show()
    sys.exit(app.exec())